<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->

    <title>搜索</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">

</head>

<body>
<!-- page header start-->
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index">主页</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
            <ul class="nav navbar-nav navbar-right">
                <%
                    String user = (String) request.getSession().getAttribute("user");
                    if (user == null || user.equals("")) {
                %>
                <li><a href="login.jsp">登录</a></li>
                <li><a href="register.jsp">注册</a></li>
                <%
                } else {
                %>
                <li><a href=""><%=request.getSession().getAttribute("user")%>
                </a></li>
                <li><a href="edit.jsp">发新闻稿</a></li>
                <%
                    if ((boolean) request.getSession().getAttribute("manager")) {
                %>
                <li><a href="manager.jsp">管理</a></li>
                <%
                    }
                %>
                <li><a href="logout">退出</a></li>
                <%
                    }
                %>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</nav>
<!-- page header end-->


<div class="container" style="margin-top: 10px">

    <div class="row">
        <div class="panel panel-default">
            <div class="panel-heading">搜索结果</div>

            <div class="panel-body">

                <form action="search" method="post">
                    <div class="input-group col-lg-6">
                        <input type="text" class="form-control" placeholder="搜索..." name="title">
                        <span class="input-group-btn">
                      <button class="btn btn-info" type="submit">搜索</button>
                    </span>
                    </div>
                </form>
                <!-- /input-group -->

                <%
                    ArrayList<HashMap<String, Object>> result = (ArrayList<HashMap<String, Object>>) request.getSession().getAttribute("search");
                    Iterator<HashMap<String, Object>> iterator = result.iterator();
                    HashMap<String, Object> temp;
                    while (iterator.hasNext()) {
                        temp = iterator.next();
                        String main = temp.get("main").toString();
                        int length = main.length();
                        main = main.substring(0, length > 32 ? 32 : length);
                %>
                <div class="panel panel-info">
                    <div class="panel-heading">
                        <a class="panel-title" href="assinfo.jsp?name=<%=temp.get("title")%>"><%=temp.get("title")%>
                        </a>
                    </div>
                    <div class="panel-body">
                        <p style="font-size:20px;"><%=main%>
                        </p>
                    </div>
                    <div class="panel-footer"><%=temp.get("feed_time")%>
                    </div>
                </div>
                <%
                    }
                %>
            </div>
        </div>
    </div>

</div> <!-- /container -->

<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
